﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=60",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab1 = tabs.getTab("tab$html");
                    var tab2 = tabs.getTab("tab$60");
                    tab2.enabled = true;
                    tabs.removeTab(tab1);
                    tabs.activeTab(tab2);
                }
            }
        });
        var str = window.location.search;
        var arr = str.split("=");
        var type = arr[1].substr(0, arr[1].indexOf('&'));
        var AdType = [{ id: 1, text: '资讯左侧图片广告' }, { id: 2, text: 'LOGO条右侧广告' }, { id: 3, text: '导航条下侧通栏广告' }, { id: 4, text: '搜索栏下侧通栏广告(1)' }, { id: 5, text: '搜索栏下侧通栏广告(2)' }, { id: 6, text: '搜索栏下侧通栏广告(4)' }, { id: 7, text: '搜索栏下侧通栏广告(6)' }, { id: 8, text: 'VIP招聘下侧通栏广告' }, { id: 9, text: '左右两侧挂边广告'}];
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td>
                    单位名称：
                    <input class="mini-textbox" id="key" emptytext="关键字" />
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-ok" plain="true" onclick="setRows(1);">设置</a>
                    <a class="mini-button" iconcls="icon-undo" plain="true" onclick="setRows(0)">取消</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetAdList">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="ad_title" width="150px" headeralign="center" align="center" allowsort="true" renderer="onNameRenderer">单位名称</div>
                <div field="ad_type" width="100px" headeralign="center" align="center" allowsort="true" renderer="onAdRenderer">广告类型</div>
                <div field="ad_hide" width="50px" headeralign="center" align="center" allowsort="true" renderer="onHideRenderer">状态</div>
                <div field="ad_url" headeralign="center" align="center" allowsort="true">链接地址</div>
                <div field="ad_img" width="50px" headeralign="center" align="center" allowsort="true" renderer="onPicRenderer">图片</div>
                <div field="ad_hits" width="100px" headeralign="center" align="center" allowsort="true">点击数</div>
                <div field="ad_effecttime" width="100px" headeralign="center" align="center" allowsort="true">有效期(天)</div>
                <div field="ad_inserttime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">添加时间</div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        var grid = mini.get("datagrid1");
        search();

        function search() {
            var key = mini.get("key").getValue();
            grid.load({ key: key, type: type });
            grid.sortBy("ad_orderid", "desc");
        }

        function onNameRenderer(e) {
            var record = e.record;
            var s;
            if (record.ad_url != null && record.ad_url != "")
                s = '<a class="linelink" target="_blank" href="' + record.ad_url + '">' + record.ad_title + '</a>';
            else
                s = '<a class="linelink" target="_blank" href="../../Web/Company/' + record.ad_no + '.html">' + record.ad_title + '</a>';
            if (record.ad_select != null && record.ad_select > 0)
                s = s + '<font color="#ff0000">[设置]</font>';
            return s;
        }

        function onPicRenderer(e) {
            var record = e.record;
            var s = '未上传';
            if (record.ad_img != null && record.ad_img != '')
                s = '<a class="linelink" target="_blank" href="' + record.ad_img + '">查看</a>';
            return s;
        }

        function setRows(state) {
            var rows = grid.getSelecteds();
            var msg = "设置";
            if (state == 0)
                msg = "取消";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选广告？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].ad_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=SelectAd",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "广告" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "广告" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "广告" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的广告！", 2);
        }
    </script>
</body>
</html>